//### This file created by BYACC 1.8(/Java extension  1.15)
//### Java capabilities added 7 Jan 97, Bob Jamison
//### Updated : 27 Nov 97  -- Bob Jamison, Joe Nieten
//###           01 Jan 98  -- Bob Jamison -- fixed generic semantic constructor
//###           01 Jun 99  -- Bob Jamison -- added Runnable support
//###           06 Aug 00  -- Bob Jamison -- made state variables class-global
//###           03 Jan 01  -- Bob Jamison -- improved flags, tracing
//###           16 May 01  -- Bob Jamison -- added custom stack sizing
//###           04 Mar 02  -- Yuval Oren  -- improved java performance, added options
//###           14 Mar 02  -- Tomas Hurka -- -d support, static initializer workaround
//### Please send bug reports to tom@hukatronic.cz
//### static char yysccsid[] = "@(#)yaccpar	1.8 (Berkeley) 01/20/90";



package generatoreLALR;



//#line 2 "src/generatoreLALR/Parser.y"
import java.io.*;
import tree.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Vector;
import java.util.Iterator;
//#line 24 "Parser.java"




public class Parser
{

boolean yydebug;        //do I want debug output?
int yynerrs;            //number of errors so far
int yyerrflag;          //was there an error?
int yychar;             //the current working character

//########## MESSAGES ##########
//###############################################################
// method: debug
//###############################################################
void debug(String msg)
{
  if (yydebug)
    System.out.println(msg);
}

//########## STATE STACK ##########
final static int YYSTACKSIZE = 500;  //maximum stack size
int statestk[] = new int[YYSTACKSIZE]; //state stack
int stateptr;
int stateptrmax;                     //highest index of stackptr
int statemax;                        //state when highest index reached
//###############################################################
// methods: state stack push,pop,drop,peek
//###############################################################
final void state_push(int state)
{
  try {
		stateptr++;
		statestk[stateptr]=state;
	 }
	 catch (ArrayIndexOutOfBoundsException e) {
     int oldsize = statestk.length;
     int newsize = oldsize * 2;
     int[] newstack = new int[newsize];
     System.arraycopy(statestk,0,newstack,0,oldsize);
     statestk = newstack;
     statestk[stateptr]=state;
  }
}
final int state_pop()
{
  return statestk[stateptr--];
}
final void state_drop(int cnt)
{
  stateptr -= cnt; 
}
final int state_peek(int relative)
{
  return statestk[stateptr-relative];
}
//###############################################################
// method: init_stacks : allocate and prepare stacks
//###############################################################
final boolean init_stacks()
{
  stateptr = -1;
  val_init();
  return true;
}
//###############################################################
// method: dump_stacks : show n levels of the stacks
//###############################################################
void dump_stacks(int count)
{
int i;
  System.out.println("=index==state====value=     s:"+stateptr+"  v:"+valptr);
  for (i=0;i<count;i++)
    System.out.println(" "+i+"    "+statestk[i]+"      "+valstk[i]);
  System.out.println("======================");
}


//########## SEMANTIC VALUES ##########
//public class ParserVal is defined in ParserVal.java


String   yytext;//user variable to return contextual strings
ParserVal yyval; //used to return semantic vals from action routines
ParserVal yylval;//the 'lval' (result) I got from yylex()
ParserVal valstk[];
int valptr;
//###############################################################
// methods: value stack push,pop,drop,peek.
//###############################################################
void val_init()
{
  valstk=new ParserVal[YYSTACKSIZE];
  yyval=new ParserVal();
  yylval=new ParserVal();
  valptr=-1;
}
void val_push(ParserVal val)
{
  if (valptr>=YYSTACKSIZE)
    return;
  valstk[++valptr]=val;
}
ParserVal val_pop()
{
  if (valptr<0)
    return new ParserVal();
  return valstk[valptr--];
}
void val_drop(int cnt)
{
int ptr;
  ptr=valptr-cnt;
  if (ptr<0)
    return;
  valptr = ptr;
}
ParserVal val_peek(int relative)
{
int ptr;
  ptr=valptr-relative;
  if (ptr<0)
    return new ParserVal();
  return valstk[ptr];
}
final ParserVal dup_yyval(ParserVal val)
{
  ParserVal dup = new ParserVal();
  dup.ival = val.ival;
  dup.dval = val.dval;
  dup.sval = val.sval;
  dup.obj = val.obj;
  return dup;
}
//#### end semantic value section ####
public final static short NL=257;
public final static short NUMBER=258;
public final static short PIU=259;
public final static short MENO=260;
public final static short PER=261;
public final static short DIVISO=262;
public final static short YYERRCODE=256;
final static short yylhs[] = {                           -1,
    0,    0,    2,    2,    1,    1,    1,    1,    1,
};
final static short yylen[] = {                            2,
    0,    2,    1,    2,    1,    3,    3,    3,    3,
};
final static short yydefred[] = {                         1,
    0,    3,    5,    0,    2,    4,    0,    0,    0,    0,
    0,    0,    0,    0,
};
final static short yydgoto[] = {                          1,
    4,    5,
};
final static short yysindex[] = {                         0,
 -231,    0,    0, -257,    0,    0, -228, -228, -228, -228,
 -233, -233, -233, -233,
};
final static short yyrindex[] = {                         0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
 -247, -243, -239, -235,
};
final static short yygindex[] = {                         0,
   -1,    0,
};
final static int YYTABLESIZE=30;
static short yytable[];
static { yytable();}
static void yytable(){
yytable = new short[]{                          6,
    0,    7,    8,    9,   10,   11,   12,   13,   14,    6,
    0,    6,    6,    7,    0,    7,    7,    8,    0,    8,
    8,    9,    0,    9,    9,    2,    3,    9,   10,    3,
};
}
static short yycheck[];
static { yycheck(); }
static void yycheck() {
yycheck = new short[] {                        257,
   -1,  259,  260,  261,  262,    7,    8,    9,   10,  257,
   -1,  259,  260,  257,   -1,  259,  260,  257,   -1,  259,
  260,  257,   -1,  259,  260,  257,  258,  261,  262,  258,
};
}
final static short YYFINAL=1;
final static short YYMAXTOKEN=262;
final static String yyname[] = {
"end-of-file",null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,"NL","NUMBER","PIU","MENO","PER","DIVISO",
};
final static String yyrule[] = {
"$accept : input",
"input :",
"input : input line",
"line : NL",
"line : exp NL",
"exp : NUMBER",
"exp : exp PIU exp",
"exp : exp MENO exp",
"exp : exp PER exp",
"exp : exp DIVISO exp",
};

//#line 89 "src/generatoreLALR/Parser.y"
private ScannerLex lexer;
private boolean first = true;

HashMap idMap = new HashMap();

//NTree<Nodo> tree = new NTree<Nodo>();

NTree<Nodo> tree = new NTree<Nodo>();

TreeUtil<Nodo> util = new TreeUtil<Nodo>();

BTree<Nodo> btree = new BTree<Nodo>();
TreeUtil<Nodo> butil = new TreeUtil<Nodo>();

public Parser(Reader r, boolean debugMe) {
	lexer = new ScannerLex(r,this);
	yydebug=debugMe;
        tree = new NTree<Nodo>();
}

public Parser(Reader r, boolean debugMe, NTree tree) {
	lexer = new ScannerLex(r,this);
	yydebug=debugMe;
        this.tree = tree;
}

public ScannerLex getScanner() {
	return lexer;
}

private int yylex () {
    int yyl_return = -1;
    try {
      yylval = new ParserVal(0);
      yyl_return = lexer.yylex();
    //System.out.println("yyl_return"+yyl_return);
    }
    catch (IOException e) {
      System.err.println("IO error :"+e);
    }
    return yyl_return;
  }
  
  public void yyerror (String error) {
    System.err.println ("Error: " + error);
  }
  
  
  
  private void addNode(String valore) {
       String [] stringval= new String[1];
       stringval[0] = valore;
  	Nodo nd = new Nodo(stringval);
  	if(first) {
  		Node<Nodo> root = tree.addRoot(nd);
  		first = false;
  	}
  	else {
  		
  		Node<Nodo> child = tree.addChildren(tree.root(),nd);
  	}
  	
  	System.out.println("NODO");
  }
  


private void addNode(Vector<String> vector) {
      
        if(vector.size()>0) {
            
            Nodo child = null;
            Nodo rootN = null;
            
            if(tree.isEmpty()) {
                
                rootN = new Nodo(vector.firstElement());
                Node<Nodo> root = tree.addRoot(rootN);
                

                

                for(int i=1; i<vector.size(); i++){

                        child = new Nodo((String)vector.get(i));
                        System.out.println("NOME CHILD: "+child.getNome());
                        System.out.println("NOME ROOT: "+rootN.getNome());
                        //if(!child.getNome().equals(rootN.getNome()))
                            tree.addChildren(root,child);
                    }
                
            }
            else {

                //System.out.println("ELSE ADD NODE");
                rootN = new Nodo(vector.firstElement());
                if(tree.root().getElement().toString().equals(rootN.toString()))
                    return;
                Node<Nodo> root = tree.changeRoot(rootN);
            



                for(int i=1; i<vector.size(); i++){
                        Boolean bool = true;
                        child = new Nodo((String)vector.get(i));
                        System.out.println("NOME CHILD: "+child.getNome());
                        System.out.println("NOME ROOT: "+rootN.getNome());
                        Iterator it = tree.children(root).iterator();
                        while (it.hasNext()) {
                            Node<Nodo> nd;
                            nd = (Node<Nodo>) it.next();
                                if(nd.getElement().getNome().equals(child.getNome()))
                                bool=false;
                        }
                        
                        if(bool)
                            tree.addChildren(root,child);
                        
                    }
            
            }
            //util.stampa(tree);
        }
        
  }
  
  private void addNode(String valore,String sx,String op,String dx) {
  	System.out.println("VAL: "+valore+" SX: "+sx+" OP: "+op+" DX: "+dx+" FIRST: "+first);
  	
	if(first) {
		//Nodo rootN = new Nodo(op,valore);
                
//		Nodo bn1N = new Nodo(stringdx);
	//	Nodo bn2N = new Nodo(stringsx);
		//BNode<Nodo> broot = btree.addRoot(rootN);
		//BNode<Nodo> bn1 = btree.insertLeft(broot, bn1N);
		//BNode<Nodo> bn2 = btree.insertRight(broot, bn2N);
	
		//butil.stampa(btree);
	
                String [] stringval= new String[1];
                String [] stringop= new String[1];
                String [] stringdx= new String[1];
                String [] stringsx= new String[1];
                stringdx[0] = dx;
                stringsx[0] = sx;
                stringval[0] = valore;
                stringop[0] = op;
		Nodo rootN = new Nodo(stringval);
		Nodo leftN = new Nodo(stringsx);
		Nodo rightN = new Nodo(stringdx);
		Nodo opN = new Nodo(stringop);
		Node<Nodo> root = tree.addRoot(rootN);
		Node<Nodo> left = tree.addChildren(root,leftN);
		Node<Nodo> operatore = tree.addChildren(root,opN);
		Node<Nodo> right = tree.addChildren(root,rightN);
		first = false;
		//util.stampa(tree);
		
	}
	//In questo caso cambio la root in quanto la costruzione e' bottomUp
	else {
		
		//Nodo rootN = new Nodo(op,valore);
//		Nodo bn1N = new Nodo(dx);
	//	Nodo bn2N = new Nodo(sx);
		//BNode<Nodo> broot = btree.changeRoot(rootN);
		//BNode<Nodo> bn1 = btree.insertLeft(broot, bn1N);
		//BNode<Nodo> bn2 = btree.insertRight(broot, bn2N);
		
		//butil.stampa(btree);
	


                String [] stringval= new String[1];
                String [] stringop= new String[1];
                String [] stringdx= new String[1];
                String [] stringsx= new String[1];
                stringdx[0] = dx;
                stringsx[0] = sx;
                stringval[0] = valore;
                stringop[0] = op;
	
		Nodo rootN = new Nodo(stringval);
		//Nodo leftN = new Nodo(stringsx);
		Nodo rightN = new Nodo(stringdx);
		Nodo opN = new Nodo(stringop);
	
		Node<Nodo> root = tree.changeRoot(rootN);
		//System.out.println("1");
		//util.stampa(tree);
		Node<Nodo> operatore = tree.addChildren(root,opN);
		//System.out.println("2");
		//util.stampa(tree);
		Node<Nodo> right = tree.addChildren(root,rightN);
		//System.out.println("3");
		//util.stampaNodi(tree);
	}
    }

        
private void addNode(String valore,String sx,String dx) {
  	  	
	if(first) {
		//Nodo rootN = new Nodo(op,valore);
                
//		Nodo bn1N = new Nodo(stringdx);
	//	Nodo bn2N = new Nodo(stringsx);
		//BNode<Nodo> broot = btree.addRoot(rootN);
		//BNode<Nodo> bn1 = btree.insertLeft(broot, bn1N);
		//BNode<Nodo> bn2 = btree.insertRight(broot, bn2N);
	
		//butil.stampa(btree);
	
                String [] stringval= new String[1];
        
                String [] stringdx= new String[1];
                String [] stringsx= new String[1];
                stringdx[0] = dx;
                stringsx[0] = sx;
                stringval[0] = valore;
        
		Nodo rootN = new Nodo(stringval);
		Nodo leftN = new Nodo(stringsx);
		Nodo rightN = new Nodo(stringdx);
	
		Node<Nodo> root = tree.addRoot(rootN);
		Node<Nodo> left = tree.addChildren(root,leftN);
	
		Node<Nodo> right = tree.addChildren(root,rightN);
		first = false;
		//util.stampa(tree);
		
	}
	//In questo caso cambio la root in quanto la costruzione e' bottomUp
	else {
		
		//Nodo rootN = new Nodo(op,valore);
//		Nodo bn1N = new Nodo(dx);
	//	Nodo bn2N = new Nodo(sx);
		//BNode<Nodo> broot = btree.changeRoot(rootN);
		//BNode<Nodo> bn1 = btree.insertLeft(broot, bn1N);
		//BNode<Nodo> bn2 = btree.insertRight(broot, bn2N);
		
		//butil.stampa(btree);
	


                String [] stringval= new String[1];
        
                String [] stringdx= new String[1];
                String [] stringsx= new String[1];
                stringdx[0] = dx;
                stringsx[0] = sx;
                stringval[0] = valore;
        
	
		Nodo rootN = new Nodo(stringval);
		//Nodo leftN = new Nodo(stringsx);
		Nodo rightN = new Nodo(stringdx);
		
		Node<Nodo> root = tree.changeRoot(rootN);
		//System.out.println("1");
		//util.stampa(tree);
	
		//System.out.println("2");
		//util.stampa(tree);
		Node<Nodo> right = tree.addChildren(root,rightN);
		//System.out.println("3");
		//util.stampaNodi(tree);
	}
        util.stampa(tree);
    }



        private void addIdToMap(String id,double val) {
            idMap.put(id,val);
        }

        private double getIdFromMap(String id) {
            if(idMap.containsKey(id))
                return (double)idMap.get(id);
            else
                return 0;
        }
//#line 465 "Parser.java"
//###############################################################
// method: yylexdebug : check lexer state
//###############################################################
void yylexdebug(int state,int ch)
{
String s=null;
  if (ch < 0) ch=0;
  if (ch <= YYMAXTOKEN) //check index bounds
     s = yyname[ch];    //now get it
  if (s==null)
    s = "illegal-symbol";
  debug("state "+state+", reading "+ch+" ("+s+")");
}





//The following are now global, to aid in error reporting
int yyn;       //next next thing to do
int yym;       //
int yystate;   //current parsing state from state table
String yys;    //current token string


//###############################################################
// method: yyparse : parse input and execute indicated items
//###############################################################
int yyparse()
{
boolean doaction;
  init_stacks();
  yynerrs = 0;
  yyerrflag = 0;
  yychar = -1;          //impossible char forces a read
  yystate=0;            //initial state
  state_push(yystate);  //save it
  val_push(yylval);     //save empty value
  while (true) //until parsing is done, either correctly, or w/error
    {
    doaction=true;
    if (yydebug) debug("loop"); 
    //#### NEXT ACTION (from reduction table)
    for (yyn=yydefred[yystate];yyn==0;yyn=yydefred[yystate])
      {
      if (yydebug) debug("yyn:"+yyn+"  state:"+yystate+"  yychar:"+yychar);
      if (yychar < 0)      //we want a char?
        {
        yychar = yylex();  //get next token
        if (yydebug) debug(" next yychar:"+yychar);
        //#### ERROR CHECK ####
        if (yychar < 0)    //it it didn't work/error
          {
          yychar = 0;      //change it to default string (no -1!)
          if (yydebug)
            yylexdebug(yystate,yychar);
          }
        }//yychar<0
      yyn = yysindex[yystate];  //get amount to shift by (shift index)
      if ((yyn != 0) && (yyn += yychar) >= 0 &&
          yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
        {
        if (yydebug)
          debug("state "+yystate+", shifting to state "+yytable[yyn]);
        //#### NEXT STATE ####
        yystate = yytable[yyn];//we are in a new state
        state_push(yystate);   //save it
        val_push(yylval);      //push our lval as the input for next rule
        yychar = -1;           //since we have 'eaten' a token, say we need another
        if (yyerrflag > 0)     //have we recovered an error?
           --yyerrflag;        //give ourselves credit
        doaction=false;        //but don't process yet
        break;   //quit the yyn=0 loop
        }

    yyn = yyrindex[yystate];  //reduce
    if ((yyn !=0 ) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
      {   //we reduced!
      if (yydebug) debug("reduce");
      yyn = yytable[yyn];
      doaction=true; //get ready to execute
      break;         //drop down to actions
      }
    else //ERROR RECOVERY
      {
      if (yyerrflag==0)
        {
        yyerror("syntax error");
        yynerrs++;
        }
      if (yyerrflag < 3) //low error count?
        {
        yyerrflag = 3;
        while (true)   //do until break
          {
          if (stateptr<0)   //check for under & overflow here
            {
            yyerror("stack underflow. aborting...");  //note lower case 's'
            return 1;
            }
          yyn = yysindex[state_peek(0)];
          if ((yyn != 0) && (yyn += YYERRCODE) >= 0 &&
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
            {
            if (yydebug)
              debug("state "+state_peek(0)+", error recovery shifting to state "+yytable[yyn]+" ");
            yystate = yytable[yyn];
            state_push(yystate);
            val_push(yylval);
            doaction=false;
            break;
            }
          else
            {
            if (yydebug)
              debug("error recovery discarding state "+state_peek(0)+" ");
            if (stateptr<0)   //check for under & overflow here
              {
              yyerror("Stack underflow. aborting...");  //capital 'S'
              return 1;
              }
            state_pop();
            val_pop();
            }
          }
        }
      else            //discard this token
        {
        if (yychar == 0)
          return 1; //yyabort
        if (yydebug)
          {
          yys = null;
          if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
          if (yys == null) yys = "illegal-symbol";
          debug("state "+yystate+", error recovery discards token "+yychar+" ("+yys+")");
          }
        yychar = -1;  //read another
        }
      }//end error recovery
    }//yyn=0 loop
    if (!doaction)   //any reason not to proceed?
      continue;      //skip action
    yym = yylen[yyn];          //get count of terminals on rhs
    if (yydebug)
      debug("state "+yystate+", reducing "+yym+" by rule "+yyn+" ("+yyrule[yyn]+")");
    if (yym>0)                 //if count of rhs not 'nil'
      yyval = val_peek(yym-1); //get current semantic value
    yyval = dup_yyval(yyval); //duplicate yyval if ParserVal is used as semantic value
    switch(yyn)
      {
//########## USER-SUPPLIED ACTIONS ##########
case 1:
//#line 28 "src/generatoreLALR/Parser.y"
{
		
		Vector<String> attributi = new Vector<>();}
break;
case 2:
//#line 31 "src/generatoreLALR/Parser.y"
{
		
		Vector<String> attributi = new Vector<>();
		attributi.add(new String(""));}
break;
case 3:
//#line 37 "src/generatoreLALR/Parser.y"
{
		
		Vector<String> attributi = new Vector<>();
		attributi.add(new String(""));}
break;
case 4:
//#line 41 "src/generatoreLALR/Parser.y"
{
		
		Vector<String> attributi = new Vector<>();
		attributi.add(new String(""));
		attributi.add(new String(Double.toString(val_peek(1).dval)));}
break;
case 5:
//#line 48 "src/generatoreLALR/Parser.y"
{yyval.dval = val_peek(0).dval;
				System.out.println(Double.toString(yyval.dval));
		Vector<String> attributi = new Vector<>();
		attributi.add(new String(Double.toString(yyval.dval)));
		attributi.add(new String(""));
		attributi.add(new String(Double.toString(val_peek(0).dval)));}
break;
case 6:
//#line 54 "src/generatoreLALR/Parser.y"
{yyval.dval = val_peek(2).dval+val_peek(0).dval;
				System.out.println(Double.toString(yyval.dval));
		Vector<String> attributi = new Vector<>();
		attributi.add(new String(Double.toString(yyval.dval)));
		attributi.add(new String(Double.toString(val_peek(2).dval)));
		attributi.add(new String("+"));
		attributi.add(new String(Double.toString(val_peek(0).dval)));;
		this.addNode(attributi);}
break;
case 7:
//#line 62 "src/generatoreLALR/Parser.y"
{yyval.dval = val_peek(2).dval-val_peek(0).dval;
				System.out.println(Double.toString(yyval.dval));
		Vector<String> attributi = new Vector<>();
		attributi.add(new String(Double.toString(yyval.dval)));
		attributi.add(new String(Double.toString(val_peek(2).dval)));
		attributi.add(new String("-"));
		attributi.add(new String(Double.toString(val_peek(0).dval)));;
		this.addNode(attributi);}
break;
case 8:
//#line 70 "src/generatoreLALR/Parser.y"
{yyval.dval = val_peek(2).dval*val_peek(0).dval;
				System.out.println(Double.toString(yyval.dval));
		Vector<String> attributi = new Vector<>();
		attributi.add(new String(Double.toString(yyval.dval)));
		attributi.add(new String(Double.toString(val_peek(2).dval)));
		attributi.add(new String("*"));
		attributi.add(new String(Double.toString(val_peek(0).dval)));;
		this.addNode(attributi);}
break;
case 9:
//#line 78 "src/generatoreLALR/Parser.y"
{yyval.dval = val_peek(2).dval/val_peek(0).dval;
				System.out.println(Double.toString(yyval.dval));
		Vector<String> attributi = new Vector<>();
		attributi.add(new String(Double.toString(yyval.dval)));
		attributi.add(new String(Double.toString(val_peek(2).dval)));
		attributi.add(new String("/"));
		attributi.add(new String(Double.toString(val_peek(0).dval)));;
		this.addNode(attributi);}
break;
//#line 695 "Parser.java"
//########## END OF USER-SUPPLIED ACTIONS ##########
    }//switch
    //#### Now let's reduce... ####
    if (yydebug) debug("reduce");
    state_drop(yym);             //we just reduced yylen states
    yystate = state_peek(0);     //get new state
    val_drop(yym);               //corresponding value drop
    yym = yylhs[yyn];            //select next TERMINAL(on lhs)
    if (yystate == 0 && yym == 0)//done? 'rest' state and at first TERMINAL
      {
      if (yydebug) debug("After reduction, shifting from state 0 to state "+YYFINAL+"");
      yystate = YYFINAL;         //explicitly say we're done
      state_push(YYFINAL);       //and save it
      val_push(yyval);           //also save the semantic value of parsing
      if (yychar < 0)            //we want another character?
        {
        yychar = yylex();        //get next character
        if (yychar<0) yychar=0;  //clean, if necessary
        if (yydebug)
          yylexdebug(yystate,yychar);
        }
      if (yychar == 0)          //Good exit (if lex returns 0 ;-)
         break;                 //quit the loop--all DONE
      }//if yystate
    else                        //else not done yet
      {                         //get next state and push, for next yydefred[]
      yyn = yygindex[yym];      //find out where to go
      if ((yyn != 0) && (yyn += yystate) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
        yystate = yytable[yyn]; //get new state
      else
        yystate = yydgoto[yym]; //else go to new defred
      if (yydebug) debug("after reduction, shifting from state "+state_peek(0)+" to state "+yystate+"");
      state_push(yystate);     //going again, so push state & val...
      val_push(yyval);         //for next action
      }
    }//main loop
  return 0;//yyaccept!!
}
//## end of method parse() ######################################



//## run() --- for Thread #######################################
/**
 * A default run method, used for operating this parser
 * object in the background.  It is intended for extending Thread
 * or implementing Runnable.  Turn off with -Jnorun .
 */
public void run()
{
  yyparse();
}
//## end of method run() ########################################



//## Constructors ###############################################
/**
 * Default constructor.  Turn off with -Jnoconstruct .

 */
public Parser()
{
  //nothing to do
}


/**
 * Create a parser, setting the debug to true or false.
 * @param debugMe true for debugging, false for no debug.
 */
public Parser(boolean debugMe)
{
  yydebug=debugMe;
}
//###############################################################



}
//################### END OF CLASS ##############################
